<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Mihail Markitan
 * Date: 10/30/11
 * Time: 9:02 PM
 */
?>
<?php
$taxcode = Taxcodes::model()->findByPk($model->taxcode);
$taxcode = json_encode($taxcode->attributes);
?>

<?php Yii::app()->clientScript->registerScript('info',<<<HERE
            var type='$type';
            taxcode=$taxcode;
            itemPriceCode='{$model->pricecode}';
            var custno='$model->custno';
            invoice='$model->invoice';    
            var editable=0;
HERE
        ,CClientScript::POS_HEAD);?>

<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/invoicetechnician.js', CClientScript::POS_BEGIN); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/invoicesItems.js', CClientScript::POS_BEGIN); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/invoicesFunctions.js', CClientScript::POS_BEGIN); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/invoiceupdate.js', CClientScript::POS_BEGIN); ?>
<div id="left-col">
<?php
$this->renderPartial('_side', array(
    'location' => $model->location,
    'customer' => $model->location->customer,
    'action' => 'view',
    'model' => $model,
    'type'=>$type
));
?>


</div>

<div id="right-col">

    <div class="wrap">
        <div class="container">


            <div id="breadcrumb" style="display:none;"><span style="padding-left:10px;font-size:10px;color:#777777;" id="alsoviewing"></span></div>
            <div class="inside">
                <?php
                $form = $this->beginWidget('CActiveForm', array(
                    'id' => 'invoice-form',
                    'enableAjaxValidation' => true,
                        ));
                ?>
                <h1>Update <?=$tabName?>: <?=$model->invoice?>
                    
                </h1>


                <div class="form">
                    


                    <div class="row" style="height:80px">
                        <table style=" width: 755px;">
                            <tr>
                                <td style=" width: 363px;">
                                    <?php echo $form->labelEx($model, 'billloc', array('style' => 'width: 100px;')); ?>
                                    <br clear="all"/>
                                    <?php
                                    $customer = Customers::model()->findByPk($model->custno);

                                    $data = $model->getBillToList($model->location->custno);
                                    ?>
                                    <div class="model-data" style="width:500px">
                                        <?=$data[$model->billloc]?>
                                    </div>
                                    
                                    <br clear="all"/>
                                    <span id='billadd1'></span><br/>
                                    <span id='billadd2'></span><br/>
                                    <span id='billcsz'></span><br/>
                                </td>
                                <td >

                                    <label>Ship To</label>

                                    <br clear="all"/>
                                    <div class="model-data">
                                        <?= $model->shipname ?>
                                    </div>
                                    <br clear="all"/>
                                    <?= $model->shipaddress1 ?><br/>
                                    <?= $model->shipaddress2 ?><br/>
                                    <?= $model->shipCSZ ?><br/>
                                </td>

                            </tr>
                        </table>

                    </div>
                    <br clear="both"/>  <br clear="both"/> <br clear="both"/>
                    <div class="left-column">
                        <div class="row short">
                            <label><?=$tabName?> Number</label>
                            <div class="model-data">
                                <?php echo $model->invoice; ?>
                            </div>
                            
                            


                        </div>
                        <div class="row short">
                            <label><?=$tabName?> Date</label>
                            <div class="model-data">
                                <?php echo $model->invoicedate;?>
                            </div>
                            



                        </div>
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'department'); ?>
                            <div class="model-data">
                                <?php echo $model->departments[$model->department];?>
                            </div>


                        </div>
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'taxcode'); ?>
                            <div class="model-data">
                                <?php echo $model->taxCodeList[$model->taxcode]; ?>
                            </div>
                            


                        </div>
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'jobnumber'); ?>
                            <div class="model-data">
                                <?php 
                                $jobList=Jobs::getList();
                                if(isset($jobList[$model->jobnumber])) echo $jobList[$model->jobnumber]; ?>
                            </div>
                            
                            

                        </div>
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'ponumber'); ?>
                            <div class="model-data">
                                <?php echo $model->ponumber; ?>
                            </div>
                            
                            

                            <?php //echo CHtml::submitButton($model->isNewRecord ? 'Create Invoice' : 'Save', array('align' => 'left')); ?>

                        </div>
                        
                    </div>
                    <div class="right-column">
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'agreementno'); ?>
                            
                        </div>
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'pricecode'); ?>
                            <div class='model-data'><?php echo $model->pricecode; ?></div>
                           
                        </div>
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'salesperson'); ?>
                            <div class="model-data">
                                <?php
                                $data = Customers::model()->getSalePersonList();
                                echo $data[$model->salesperson];
                                ?>
                            </div>
                        </div>
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'clerk'); ?>
                            <div class="model-data">
                                <?php echo Employees::getEmployeeName($model->clerk); ?>
                            </div>

                        </div>
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'slterms'); ?>
                            <div class="model-data">
                                <?php 
                                $termList=Customers::model()->getTermList();
                                echo $termList[$model->slterms]; ?>
                            </div>
                        </div>
                        <?php if($model->invoicetype!=Invoice::TYPE_INVOICE):?>
                        <div class="row short">
                            <label><?=$tabName?> status</label>
                            <div class="model-data">
                                <?php 
                                $statusList=$model->getQuoteStatusList();
                                echo $statusList[$model->quotestatus];
                                ?>
                            </div>
                        </div>
                        
                        <?php
                        $style=$model->quotestatus!=Invoice::STATUS_REJECTED?'display:none':NULL;
                        ?>
                        <div id="rejectedreason" style="<?=$style?>">
                            
                            <div class="row short">
                                <?php echo $form->labelEx($model,'rejectedreason');?>
                                <div class="model-data">
                                    <?php echo $model->rejectedreason;?>
                                </div>
                            </div>
                            
                        </div>
                        <?php endif?>
                    </div>



                    <br clear="both"/>
             
                </div>
                <table style="width:700px">
                    <tr>
                        <td>Dispatch</td>
                        <td><?= $model->dispatch ?></td>
                        <td>Discount</td>
                        <td>0.00</td>
                        <td>Balance</td>
                        <td>0.00</td>
                    </tr>
                    <tr>
                        <td>Regular Hours</td>
                        <td id="regularhours"><?= InvoiceEmp::model()->getTotalRegularHours($model->invoice) ?></td>
                        <td></td>
                        <td></td>
                        <td>Over 30</td>
                        <td>0.00</td>              
                    </tr>
                    <tr>
                        <td>Overtime</td>
                        <td id="overhead"><?= InvoiceEmp::model()->getTotalRegularHours($model->invoice) ?></td>
                        <td></td>
                        <td></td>
                        <td>Over 60</td>
                        <td>0.00</td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td>Over 90</td>
                        <td>0.00</td>
                    </tr>
                </table>

                <br/>
                <ul id="tab" class="tabs tabs-with-summary">
                    <li class="active"><a href="#invoice"><?=$tabName?></a></li>
                    <li><a href="#technician">Technician</a></li>
                    <li><a href="#equipment" class='unavailable'>Equipment</a></li>
                    <li><a href="#document" class='unavailable'>Document</a></li>
                </ul>

                <br/>   
                <div id="invoice">
                    
                    <div id="item-list">

                    </div>
                </div>
                <div id="technician">
                    
                    <div id="emp-list"></div>
                </div>
                <div id="equipment"></div>
                <div id="document"></div>
                <br/>
              
                <div class="form">
                <div class="left-column" style="">
                    <?php if($model->invoicetype==INVOICE::TYPE_INVOICE):?>
                    <div class="row short">
                        <?php echo $form->labelEx($model,'hold');?>
                        <div class="model-data">
                            <?php $holdList=$model->getHoldList();
                            echo $holdList[$model->hold];
                            ?>
                        </div>
                        
                    </div>
                    <?php endif?>
                    
                    
                    
                    
                </div>
                
                <div class="right-column" style="float:right;">
                   
                    <table id="summarytable" style="width: 300px;text-align: right;float:right">


                        <tr>
                            <td>Material cost</td>
                            <td id="materialcost"></td>
                            <td>Subtotal</td>
                            <td id="subtotal"></td>


                        </tr>
                        <tr>
                            <td>Labor cost</td>
                            <td id="laborcost"></td>
                            <td>Tax</td>
                            <td id="taxtotal"></td>
                        </tr>
                        <tr>
                            <td>Other cost</td>
                            <td>0.00</td>
                            <td>Total</td>
                            <td id="total"></td>
                        </tr>
                        <tr>
                            <td>Gross Profit</td>
                            <td id="grossprofit"></td>
                        </tr>

                    </table>
                
                </div>
                
                </div>
         
                <?php $this->endWidget('CActiveForm'); ?>
            </div><!-- inside -->
        </div><!-- container -->
    </div><!-- wrap -->
    <?php $this->renderPartial('application.views.copyright'); ?>
</div> <!-- left-col -->
